package iterators;


import java.util.Iterator;

import util.HtmlTextFinder;

//Class implements iterator that must move among advertisments data
public abstract class NadlanIterator implements Iterator{	
//Class attributes
	protected HtmlTextFinder txtFinder;
	
    //true, if last title of advertisment in this buffer has already been
	//returned by next()
	protected boolean bLast;
	
	protected String curValue=null;//last value found from html table	
	protected int curType=-1;//last column/row data type found
	
//Class methods
	abstract protected String findTitle();
	
	public NadlanIterator(String buf){this(buf,true);}
	
	protected NadlanIterator(String buf,boolean bFind)
	{
		bLast=false;
		txtFinder=new HtmlTextFinder(buf);
		if(bFind)
			findTitle();
	}

	//returns column type of last advertisment data read
	public int getCurType(){return curType;}

	//returns column type of last advertisment data read
	public String getCurValue(){return curValue;}

	//true - if there is an advertisment data that has not be returned by next().
	public boolean hasNext()
	{
		if(txtFinder.getPos()>=txtFinder.getBufLen() || txtFinder.getPos()<0)
		{
			txtFinder.moveToEnd();
			bLast=true;
		}
		return !bLast;
	}
	
	//Returns last value read and find next value and title 
	public Object next()
	{	
		String str=
			(curValue==null) ? " " : curValue;
		if(!bLast)
			findTitle();		
		return str;
	}

	//Deprecated. Must remove items 
	public void remove(){}

}
